package test;

import java.util.Stack;
class MyQueue {
    private Stack<Integer> s1;
    private Stack<Integer> s2;

    public MyQueue() {
        s1 = new Stack<>();
        s2 = new Stack<>();
    }

    public void push(int x) {
        s1.push(x);
    }

    public int pop() {
        if(empty())
        {
            return -1;
        }
        if(s2.isEmpty())
        {
            while(!s1.isEmpty())
            {
                s2.push(s1.pop());
            }
        }

        return s2.pop();
    }

    public int peek() {
        if(empty())
        {
            return -1;
        }
        if(s2.isEmpty())
        {
            while(!s1.isEmpty())
            {
                s2.push(s1.pop());
            }
        }
        return s2.peek();
    }

    public boolean empty() {
        return s1.isEmpty()&& s2.isEmpty();
    }
}
public class Queuetest {
    public static void main(String[] args) {
        MyQueue q1 = new MyQueue();
        q1.push(1);
        q1.push(2);
        q1.push(3);
        q1.push(4);
        q1.pop();
        System.out.println(q1.peek());
    }
}
